//
//  NSObject+DomainTag.m
//  QTCategory
//
//  Created by 张俊博 on 2016/11/29.
//  Copyright © 2016年 CISDI. All rights reserved.
//

#import "NSObject+DomainTag.h"
#import <objc/runtime.h>
#import "NSObject+QTAssociate.h"
#import "QTCategoryMacro.h"

//static char const * const kDomainTag    =   "kDomainTag";
static NSString * const kDomainTag    =   @"kDomainTag";

@implementation NSObject (DomainTag)

- (void)setDomainTag:(NSString *)domainTag
{
    if (isNullStr(domainTag)) {
        return;
    }
    
    NSString *_domainTag = domainTag.mutableCopy;
//    self.as_dictionary[kDomainTag] = _domainTag;
    objc_setAssociatedObject(self, @selector(domainTag), _domainTag, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (NSString *)domainTag
{
    return objc_getAssociatedObject(self, @selector(domainTag));
//    return self.as_dictionary[kDomainTag];
}

@end

@implementation NSArray (DomainTag)

- (void)setDomainTag:(NSString *)domainTag
{
    if (isNullStr(domainTag)) {
        return;
    }
    NSString *_domainTag = domainTag.mutableCopy;
    [super setDomainTag:_domainTag];
    for (id obj in self) {
        [obj setDomainTag:_domainTag];
    }
}


@end

@implementation NSDictionary (DomainTag)

- (void)setDomainTag:(NSString *)domainTag
{
    if (isNullStr(domainTag)) {
        return;
    }
    NSString *_domainTag = domainTag.mutableCopy;
    [super setDomainTag:_domainTag];
    for (id obj in self.allValues) {
        [obj setDomainTag:_domainTag];
    }
}

@end
